package com.itheima.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import pojo.Order;
import utils.DateUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 统计报表服务，运营数据
 */
@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {
    
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;
    
    @Override
    public Map<String, Object> getBusinessReport() throws Exception {
        Map<String,Object> map = new HashMap<>();

        String todayDate = DateUtils.parseDate2String(new Date());
        map.put("reportDate",todayDate);//日期
        
        Integer todayNewMember = memberDao.getMemberCountByDate(todayDate);
        map.put("todayNewMember",todayNewMember);//今日新增会员数
        
        Integer totalMember = memberDao.getMemberTotalCount();
        map.put("totalMember",totalMember);//总会员数
        
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        Integer thisWeekNewMember = memberDao.getMemberCountByLaterDate(thisWeekMonday);
        map.put("thisWeekNewMember",thisWeekNewMember);//本周新增会员数
        
        String thisMonthFirstDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        Integer thisMonthNewMember = memberDao.getMemberCountByLaterDate(thisMonthFirstDay);
        map.put("thisMonthNewMember",thisMonthNewMember);//本月新增会员数
        
        Integer todayOrderNumber = orderDao.getOrderCountByDate(todayDate);
        map.put("todayOrderNumber",todayOrderNumber);//今日预约数
        
        String orderStatus = Order.ORDERSTATUS_NO;
        Integer todayVisitsNumber = orderDao.getOrderCountByDateAndStatus(todayDate,orderStatus);
        map.put("todayVisitsNumber",todayVisitsNumber);//今日到诊数
        
        
        Integer thisWeekOrderNumber = orderDao.getOrderCountByLaterDate(thisWeekMonday);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);//本周预约数
        
        Integer thisWeekVisitsNumber = orderDao.getOrderCountByLaterDateAndStatus(thisWeekMonday,orderStatus);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);//本周到诊数
        
        Integer thisMonthOrderNumber = orderDao.getOrderCountByLaterDate(thisMonthFirstDay);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);//本月预约数
        
        Integer thisMonthVisitsNumber = orderDao.getOrderCountByLaterDateAndStatus(thisMonthFirstDay,orderStatus);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);//本月到诊数
        
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        map.put("hotSetmeal",hotSetmeal);//热门套餐，前四名
        return map;
    }
    /**
     * data:{
     *                 reportData:{
     *                     reportDate:null,//日期
     *                     todayNewMember :0,//会员数据统计， 新增会员数
     *                     totalMember :0,//总会员数
     *                     thisWeekNewMember :0,//本周新增会员数
     *                     thisMonthNewMember :0,//本月新增会员数
     *
     *                     todayOrderNumber :0,//预约, 今日预约数
     *                     todayVisitsNumber :0,//今日到诊数
     *                     thisWeekOrderNumber :0,//本周预约数
     *                     thisWeekVisitsNumber :0,//本周到诊数
     *                     thisMonthOrderNumber :0,//本月预约数
     *                     thisMonthVisitsNumber :0,//本月到诊数
     *
     *                     hotSetmeal :[ //热门套餐, 套餐名称，预约数量，占比，备注
     *                         {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
     *                         {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}
     *                     ]
     *                 }
     *             },
     */
}
